//
//  AuthCommonTableViewCell.m
//  LPTClient
//
//  Created by apple on 2018/12/10.
//  Copyright © 2018 zhaodd. All rights reserved.
//

#import "AuthCommonTableViewCell.h"

@interface AuthCommonTableViewCell ()

@property (nonatomic, weak) IBOutlet UILabel *titleLab;
@property (nonatomic, weak) IBOutlet UITextField *textfield;

@end

@implementation AuthCommonTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)refreshWithDict:(NSDictionary *)dict
{
    self.titleLab.text = dict[@"name"];
    NSInteger type = [dict[@"type"] integerValue];
    NSString *v = dict[@"v"];
    
    // 给textField 添加关联对象 key 保存一下
    objc_setAssociatedObject(self.textfield, @"custom_key", dict[@"key"], OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    if (type == 1) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.accessoryType = UITableViewCellAccessoryNone;
        self.textfield.enabled = YES;
        
        NSString *holderText = self.titleLab.text;
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc] initWithString:holderText];
        [placeholder addAttribute:NSForegroundColorAttributeName
                            value:[UIColor colorWithHexString:@"#999999"]
                            range:NSMakeRange(0, holderText.length)];
        self.textfield.attributedPlaceholder = placeholder;
        self.textfield.text = v;
    }else if (type == 2) {
        self.selectionStyle = UITableViewCellSelectionStyleGray;
        self.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        self.textfield.enabled = NO;
        self.textfield.placeholder = @"";
        self.textfield.text = v;
    }
}

@end
